package com.hmyd.hmyd_android.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.dto.Article;
import com.hmyd.hmyd_android.utils.Utils;

public class HmNoticeAdapter extends BaseAdapter {
	private Context mContext;
	private List<Article> lists;
	private LayoutInflater mInflater;

	public HmNoticeAdapter(Context context, List<Article> lists) {
		this.mContext = context;
		this.lists = lists;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return lists != null ? lists.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_hmnotice_item, null);
			holder = new ViewHolder();

			holder.tv_content = (TextView) convertView.findViewById(R.id.hmnotice);
			holder.tv_time = (TextView) convertView.findViewById(R.id.hmnotice_time);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Article item = lists.get(position);
		holder.tv_content.setText(item.title);
		holder.tv_time.setText(Utils.getDateStringMinute(item.createdTime));
		return convertView;

	}

	class ViewHolder {
		public TextView tv_content;
		public TextView tv_time;

	}

}
